//
// Created by 215609 on 2024/8/17.
//

#ifndef TSAVPLAYER_AVPACKETQUEUE_H
#define TSAVPLAYER_AVPACKETQUEUE_H
using namespace std;
#include <thread>
extern "C" {
#include <libavcodec/avcodec.h>
};
typedef struct AVPacketNode {
    AVPacket pkt;
    struct AVPacketNode *next;
} AVPacketNode;


class AVPacketQueue {
public:
    AVPacketQueue();

    virtual ~AVPacketQueue();
    // 入队数据包
    int PushPacket(AVPacket *packet);
    //入队空数据包
    int PushNullPacket(int stream_index);

    //刷新
    void Flush();

    void Abort();

    void Start();


    int GetPacket(AVPacket *pkt);

    // 获取数据包
    int GetPacket(AVPacket *pkt, int block);

    int GetPacketSize();

    int GetSize();

    int64_t GetDuration();

    int IsAbort();
private:
    int Put(AVPacket *pkt);
private:
    mutex m_Mutex;
    condition_variable m_CondVar;
    AVPacketNode *first_pkt, *last_pkt;
    int nb_packets; //链表长度
    int size;   //数据大小
    int64_t duration; //总时长
    volatile int abort_request;

};


#endif //TSAVPLAYER_AVPACKETQUEUE_H
